package com.naiterui.ehp.bs.patient.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.naiterui.ehp.bs.patient.dao.IDrStarInfoDao;
import com.naiterui.ehp.bs.patient.repository.IApDrStarInfoRepository;
import com.naiterui.ehp.bs.patient.utils.ConfigKeyUtil;
import com.naiterui.ehp.bs.patient.utils.TitleUtil;
import com.naiterui.ehp.bs.patient.utils.constants.PatientConstant;
import com.naiterui.ehp.bs.patient.vo.doctor.StarInfoVO;

@Component
public class ApDrStarInfoDaoImpl implements IDrStarInfoDao {
    private static final String REWARD_IMG_DOMAIN = ConfigKeyUtil.getString(PatientConstant.REWARD_IMG_DOMAIN);

    @Autowired
    private IApDrStarInfoRepository drStarInfoRepository;

    /**
     * 查询明星医生
     * IDrStarInfoDao.findDrStarInfo()
     *
     * @param num
     *
     * @return
     *
     * @Author YongYang
     * @Date 2016年7月20日
     * @since 1.0.0
     */
    @Override
    public List<StarInfoVO> findDrStarInfo(int num) {
        List<StarInfoVO> result = new ArrayList<>();

        List<Object[]> rs = drStarInfoRepository.findDrStarInfo(num);
        for (Object[] obj : rs) {
            StarInfoVO starInfoVo = new StarInfoVO();
            starInfoVo.setTitle(obj[0] == null ? "" : TitleUtil.getTitle(Integer.parseInt(obj[0].toString())));
            starInfoVo.setName(obj[1] == null ? "" : obj[1].toString());
            String backgroundImg = REWARD_IMG_DOMAIN + obj[2].toString();
            starInfoVo.setBackgroundImg(backgroundImg);
            String fuzzyImg = REWARD_IMG_DOMAIN + obj[3].toString();
            starInfoVo.setFuzzyImg(fuzzyImg);
            starInfoVo.setDepartmentName(obj[4] == null ? "" : obj[4].toString());
            result.add(starInfoVo);
        }
        return result;
    }

}
